package com.shop.controller;

import com.shop.service.DtsOrderService;
import com.shop.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName AdminOrderController
 * @Author xiao宋
 * @Date 8:42  2022/10/24
 * @Version 1.0
 * @Description TODO
 */
@Slf4j
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {
    @Autowired
    DtsOrderService service;

    /**
     *
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @param userId    查询时候的用户 ID
     * @param orderSn   查询时候的订单编号
     * @param orderStatusArray   查询时候的订单状态
     * @return
     */
    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @RequestParam(value = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            Integer userId, Integer orderSn, Integer[] orderStatusArray
    ) {
        log.debug("前端传的用户 ID：",userId);
        log.debug("前端传的订单编号为：",orderSn);
        log.debug("前端传的订单状态为：",orderStatusArray);
        Map<String,Object>data=service.findOrderPage(page,limit,sort,order,userId,orderSn,orderStatusArray);
        return ResponseUtil.ok(data);
    }

    @GetMapping("/detail")
    public Object detail(Integer id){
        Map<String,Object>data=service.getOrderDetail(id);
        return ResponseUtil.ok(data);
    }
}
